package com.moleq.service;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.moleq.db.DBError;
import com.moleq.db.DatabaseHelper;
import com.moleq.db.DatabaseSchema;
import com.moleq.dialog.MessageDialog;
import com.moleq.dialog.MessageDialog.OnClickMessageListener;
import com.moleq.models.FixedTotalRpt;

public class FixedTotalRptService {
	private DatabaseHelper DBHelper;
	private MessageDialog mMessageDialog;
	Context context;
	
	public FixedTotalRptService(){}
	
	public FixedTotalRptService(Context context){
		this.context = context;
		this.DBHelper = new DatabaseHelper(context);
	}
	
	public void DeleteAll() {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		db.execSQL("DELETE FROM "+ DatabaseSchema.FixedTotalRpt.SCHEMA_NAME);
	}
	
	public void DeleteByID(long id) {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		db.execSQL("DELETE FROM "+ DatabaseSchema.FixedTotalRpt.SCHEMA_NAME
				+" WHERE "+ DatabaseSchema.FixedTotalRpt.ID +" = ?",
				new Object[] { id });
	}
	
	public List<FixedTotalRpt> FindAll(){
		List<FixedTotalRpt> obj = new ArrayList<FixedTotalRpt>();
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		
		Cursor cursor = db.rawQuery("select * from " + DatabaseSchema.FixedTotalRpt.SCHEMA_NAME, null);
		if (cursor == null) {
			ShowMessage(DBError.error,mMessageDialog.MESSAGE_BOX_OK,mMessageDialog.ICON_ERROR);
			DBError.error = "";
			return obj;
		}
		while (cursor.moveToNext()) {
			int ft_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.ID));
			int ft_store_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STORE_ID));
			int ft_station = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STATION));
			String ft_date = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DATE));
			int ft_gs_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_QTY));
			double ft_gs_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_AMT));
			int ft_ns_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_QTY));
			double ft_ns_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_AMT));
			double ft_cash_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CASH_ID));
			double ft_credit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CREDIT_ID));
			
			double ft_debit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DEBIT_ID));
			double ft_check_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CHECK_ID));
			double ft_foodstamp_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FOODSTAMP_ID));
			double ft_ebt_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.EBT_ID));
			double ft_gc_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GC_ID));
			int ft_refund_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_QTY));
			double ft_refund_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_AMT));
			int ft_trn_count = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TRN_COUNT));
			double ft_average = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.AVERAGE));
			double ft_discount = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DISCOUNT));
			
			double ft_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.COUPON));
			double ft_taxable_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_1));
			double ft_tax_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_1));
			double ft_tax_exem_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_1));
			double ft_taxable_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_2));
			double ft_tax_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_2));
			double ft_tax_exem_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_2));
			double ft_taxable_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_3));
			double ft_tax_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_3));
			double ft_tax_exem_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_3));
			
			double ft_taxable_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_4));
			double ft_tax_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_4));
			double ft_tax_exem_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_4));
			double ft_taxable_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_5));
			double ft_tax_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_5));
			double ft_tax_exem_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_5));
			double ft_taxable_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_6));
			double ft_tax_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_6));
			double ft_tax_exem_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_6));
			String ft_user_id = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_USER_ID));
			double ft_rounding = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_ROUNDING));
			double ft_vdr_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_VDR_COUPON));
			
			obj.add(new FixedTotalRpt(ft_id, ft_store_id, ft_station, ft_date, ft_gs_qty, ft_gs_amt, 
					ft_ns_qty, ft_ns_amt, ft_cash_id, ft_credit_id, ft_debit_id, ft_check_id, ft_foodstamp_id, 
					ft_ebt_id, ft_gc_id, ft_refund_qty, ft_refund_amt, ft_trn_count, ft_average, ft_discount, 
					ft_coupon, ft_taxable_1, ft_tax_1, ft_tax_exem_1, ft_taxable_2, ft_tax_2, ft_tax_exem_2, 
					ft_taxable_3, ft_tax_3, ft_tax_exem_3, ft_taxable_4, ft_tax_4, ft_tax_exem_4, ft_taxable_5, 
					ft_tax_5, ft_tax_exem_5, ft_taxable_6, ft_tax_6, ft_tax_exem_6, ft_user_id,ft_rounding,ft_vdr_coupon));
		}
		cursor.close();
		return obj;
	}
	
	public void InsertOrUpdate(FixedTotalRpt obj){
		if(CheckFixTotalInList(obj.getFt_date(), obj.getFt_user_id()) > 0){
			obj.setFt_id(CheckFixTotalInList(obj.getFt_date(), obj.getFt_user_id()));
			this.Update(obj);
		}else {
			this.Insert(obj);
		}
	}
		
	public void Update(FixedTotalRpt obj) {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		db.execSQL(
			"Update " + DatabaseSchema.FixedTotalRpt.SCHEMA_NAME + " set ft_date = ?,ft_gs_qty = ft_gs_qty + ?," +
					"ft_gs_amt = ft_gs_amt + ?,ft_ns_qty = ft_ns_qty + ?,ft_ns_amt = ft_ns_amt + ?,ft_cash_id = ft_cash_id + ?," +
					"ft_credit_id = ft_credit_id + ?,ft_debit_id = ft_debit_id + ?,ft_check_id = ft_check_id + ?," +
					"ft_foodstamp_id = ft_foodstamp_id + ?,ft_ebt_id = ft_ebt_id + ?,ft_gc_id = ft_gc_id + ?,"+
					"ft_refund_qty = ft_refund_qty + ?,ft_refund_amt = ft_refund_amt + ?,ft_trn_count = ft_trn_count + ?,"+
					"ft_average = ?,ft_discount = ft_discount + ?,ft_coupon = ft_coupon + ?,"+
					"ft_taxable_1 = ft_taxable_1 + ?,ft_tax_1 = ft_tax_1 + ?,ft_tax_exem_1 = ft_tax_exem_1 + ?,"+
					"ft_taxable_2 = ft_taxable_2 + ?,ft_tax_2 = ft_tax_2 + ?,ft_tax_exem_2 = ft_tax_exem_2 + ?,"+
					"ft_taxable_3 = ft_taxable_3 + ?,ft_tax_3 = ft_tax_3 + ?,ft_tax_exem_3 = ft_tax_exem_3 + ?,"+
					"ft_taxable_4 = ft_taxable_4 + ?,ft_tax_4 = ft_tax_4 + ?,ft_tax_exem_4 = ft_tax_exem_4 + ?,"+
					"ft_taxable_5 = ft_taxable_5 + ?,ft_tax_5 = ft_tax_5 + ?,ft_tax_exem_5 = ft_tax_exem_5 + ?,"+
					"ft_taxable_6 = ft_taxable_6 + ?,ft_tax_6 = ft_tax_6 + ?,ft_tax_exem_6 = ft_tax_exem_6 + ?,"+
					"ft_user_id = ?,update_datetime = strftime('%Y%m%d%H%M%S','now'),ft_rounding = ft_rounding + ?,ft_vdr_coupon = ft_vdr_coupon + ?" +
					" where ft_date = ? and ft_id = ? and ft_user_id = ?",
			new Object[] { obj.getFt_date(), obj.getFt_gs_qty(), obj.getFt_gs_amt(), obj.getFt_ns_qty(), obj.getFt_ns_amt(), 
					obj.getFt_cash_id(), obj.getFt_credit_id(), obj.getFt_debit_id(), obj.getFt_check_id(), obj.getFt_foodstamp_id(), 
					obj.getFt_ebt_id(), obj.getFt_gc_id(), obj.getFt_refund_qty(), obj.getFt_refund_amt(), obj.getFt_trn_count(), 
					obj.getFt_average(), obj.getFt_discount(), obj.getFt_coupon(), 
					obj.getFt_taxable_1(), obj.getFt_tax_1(), obj.getFt_tax_exem_1(),
					obj.getFt_taxable_2(), obj.getFt_tax_2(), obj.getFt_tax_exem_2(),
					obj.getFt_taxable_3(), obj.getFt_tax_3(), obj.getFt_tax_exem_3(),
					obj.getFt_taxable_4(), obj.getFt_tax_4(), obj.getFt_tax_exem_4(),
					obj.getFt_taxable_5(), obj.getFt_tax_5(), obj.getFt_tax_exem_5(),
					obj.getFt_taxable_6(), obj.getFt_tax_6(), obj.getFt_tax_exem_6(),
					obj.getFt_user_id(), obj.getFt_rounding(), obj.getFt_vdr_coupon(),
					obj.getFt_date(), obj.getFt_id(), obj.getFt_user_id() });
	}

	public int CheckFixTotalInList(String ft_date,String ft_user_id) {
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		
		Cursor cursor = db.rawQuery("select ft_id from " + DatabaseSchema.FixedTotalRpt.SCHEMA_NAME
				+ " where ft_date = '"+ ft_date +"' and ft_user_id = '"+ ft_user_id +"'", null);
		if (cursor == null) {
			ShowMessage(DBError.error,mMessageDialog.MESSAGE_BOX_OK,mMessageDialog.ICON_ERROR);
			DBError.error = "";
			return 0;
		}
		if (cursor.moveToNext()) {
			int id = cursor.getInt(0);
			cursor.close();
			return id;
		}
		cursor.close();
		return 0;
	}

	public FixedTotalRpt getTrnCount(String ft_date){
		double amt = 0;
		int count = 0;
		FixedTotalRpt fixedTotalRpt  = new FixedTotalRpt();
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery("select ft_ns_amt,ft_trn_count from " + DatabaseSchema.FixedTotalRpt.SCHEMA_NAME
				+ " where ft_date = '"+ ft_date +"'", null);
		if (cursor == null) {
			ShowMessage(DBError.error,mMessageDialog.MESSAGE_BOX_OK,mMessageDialog.ICON_ERROR);
			DBError.error = "";
			return null;
		}
		if (cursor.moveToNext()) {
			amt = cursor.getDouble(0);
			count = cursor.getInt(1);
		}
		fixedTotalRpt.setFt_ns_amt(amt);
		fixedTotalRpt.setFt_trn_count(count);
		cursor.close();
		return fixedTotalRpt;
	}
	public void Insert(FixedTotalRpt obj){
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		db.execSQL(
				"INSERT INTO " + DatabaseSchema.FixedTotalRpt.SCHEMA_NAME + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," +
						"?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,strftime('%Y%m%d%H%M%S','now'),strftime('%Y%m%d%H%M%S','now'),?,?,?)",
				new Object[] { null, obj.getFt_store_id(), obj.getFt_station(), obj.getFt_date(), obj.getFt_gs_qty(),
						obj.getFt_gs_amt(), obj.getFt_ns_qty(), obj.getFt_ns_amt(), obj.getFt_cash_id(), obj.getFt_credit_id(),
						obj.getFt_debit_id(), obj.getFt_check_id(), obj.getFt_foodstamp_id(), obj.getFt_ebt_id(), obj.getFt_gc_id(),
						obj.getFt_refund_qty(), obj.getFt_refund_amt(), obj.getFt_trn_count(), obj.getFt_ns_amt(), obj.getFt_discount(),
						obj.getFt_coupon(), obj.getFt_taxable_1(), obj.getFt_tax_1(), obj.getFt_tax_exem_1(), obj.getFt_taxable_2(),
						obj.getFt_tax_2(), obj.getFt_tax_exem_2(), obj.getFt_taxable_3(), obj.getFt_tax_3(), obj.getFt_tax_exem_3(),
						obj.getFt_taxable_4(), obj.getFt_tax_4(), obj.getFt_tax_exem_4(), obj.getFt_taxable_5(), obj.getFt_tax_5(),
						obj.getFt_tax_exem_5(), obj.getFt_taxable_6(), obj.getFt_tax_6(), obj.getFt_tax_exem_6(), obj.getFt_user_id(),
						obj.getFt_rounding(), obj.getFt_vdr_coupon() });
	}
	
	public List<FixedTotalRpt> getFixedTotalRepByDate(String Date){
		List<FixedTotalRpt> list = new ArrayList<FixedTotalRpt>();
//		String sql = "select * from t_fixed_total_rpt where ft_date = '" + Date + "' order by ft_id";
		String sql = "select ft_id,ft_store_id,ft_station,ft_date,sum(ft_gs_qty) as ft_gs_qty,sum(ft_gs_amt) as ft_gs_amt," +
				"sum(ft_ns_qty) as ft_ns_qty,sum(ft_ns_amt) as ft_ns_amt,sum(ft_cash_id) as ft_cash_id," +
				"sum(ft_credit_id) as ft_credit_id,sum(ft_debit_id) as ft_debit_id,sum(ft_check_id) as ft_check_id," +
				"sum(ft_foodstamp_id) as ft_foodstamp_id,sum(ft_ebt_id) as ft_ebt_id,sum(ft_gc_id) as ft_gc_id," +
				"sum(ft_refund_qty) as ft_refund_qty,sum(ft_refund_amt) as ft_refund_amt,sum(ft_trn_count) as ft_trn_count," +
				"sum(ft_average) as ft_average,sum(ft_discount) as ft_discount,sum(ft_coupon) as ft_coupon," +
				"sum(ft_taxable_1) as ft_taxable_1,sum(ft_tax_1) as ft_tax_1,sum(ft_tax_exem_1) as ft_tax_exem_1," +
				"sum(ft_taxable_2) as ft_taxable_2,sum(ft_tax_2) as ft_tax_2,sum(ft_tax_exem_2) as ft_tax_exem_2," +
				"sum(ft_taxable_3) as ft_taxable_3,sum(ft_tax_3) as ft_tax_3,sum(ft_tax_exem_3) as ft_tax_exem_3," +
				"sum(ft_taxable_4) as ft_taxable_4,sum(ft_tax_4) as ft_tax_4,sum(ft_tax_exem_4) as ft_tax_exem_4," +
				"sum(ft_taxable_5) as ft_taxable_5,sum(ft_tax_5) as ft_tax_5,sum(ft_tax_exem_5) as ft_tax_exem_5," +
				"sum(ft_taxable_6) as ft_taxable_6,sum(ft_tax_6) as ft_tax_6,sum(ft_tax_exem_6) as ft_tax_exem_6," +
				"ft_user_id,sum(ft_rounding) as ft_rounding,sum(ft_vdr_coupon) as ft_vdr_coupon from t_fixed_total_rpt" +
				" where ft_date = '" + Date + "' group by ft_date order by ft_id";
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(sql, null);
		if(cursor == null) return list;
		while (cursor.moveToNext()) {
			int ft_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.ID));
			int ft_store_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STORE_ID));
			int ft_station = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STATION));
			String ft_date = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DATE));
			int ft_gs_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_QTY));
			double ft_gs_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_AMT));
			int ft_ns_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_QTY));
			double ft_ns_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_AMT));
			double ft_cash_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CASH_ID));
			double ft_credit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CREDIT_ID));
			
			double ft_debit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DEBIT_ID));
			double ft_check_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CHECK_ID));
			double ft_foodstamp_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FOODSTAMP_ID));
			double ft_ebt_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.EBT_ID));
			double ft_gc_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GC_ID));
			int ft_refund_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_QTY));
			double ft_refund_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_AMT));
			int ft_trn_count = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TRN_COUNT));
			double ft_average = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.AVERAGE));
			double ft_discount = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DISCOUNT));
			
			double ft_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.COUPON));
			double ft_taxable_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_1));
			double ft_tax_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_1));
			double ft_tax_exem_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_1));
			double ft_taxable_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_2));
			double ft_tax_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_2));
			double ft_tax_exem_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_2));
			double ft_taxable_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_3));
			double ft_tax_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_3));
			double ft_tax_exem_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_3));
			
			double ft_taxable_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_4));
			double ft_tax_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_4));
			double ft_tax_exem_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_4));
			double ft_taxable_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_5));
			double ft_tax_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_5));
			double ft_tax_exem_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_5));
			double ft_taxable_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_6));
			double ft_tax_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_6));
			double ft_tax_exem_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_6));
			String ft_user_id = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_USER_ID));
			double ft_rounding = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_ROUNDING));
			double ft_vdr_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_VDR_COUPON));
			
			list.add(new FixedTotalRpt(ft_id, ft_store_id, ft_station, ft_date, ft_gs_qty, ft_gs_amt, 
					ft_ns_qty, ft_ns_amt, ft_cash_id, ft_credit_id, ft_debit_id, ft_check_id, ft_foodstamp_id, 
					ft_ebt_id, ft_gc_id, ft_refund_qty, ft_refund_amt, ft_trn_count, ft_average, ft_discount, 
					ft_coupon, ft_taxable_1, ft_tax_1, ft_tax_exem_1, ft_taxable_2, ft_tax_2, ft_tax_exem_2, 
					ft_taxable_3, ft_tax_3, ft_tax_exem_3, ft_taxable_4, ft_tax_4, ft_tax_exem_4, ft_taxable_5, 
					ft_tax_5, ft_tax_exem_5, ft_taxable_6, ft_tax_6, ft_tax_exem_6, ft_user_id,ft_rounding,ft_vdr_coupon));
		}
		cursor.close();
		return list;
	}
	
	public List<FixedTotalRpt> getFixedTotalRepByDate(String Date,String UserId){
		List<FixedTotalRpt> list = new ArrayList<FixedTotalRpt>();
//		String sql = "select * from t_fixed_total_rpt where ft_date = '" + Date + "' order by ft_id";
		String sql = "select ft_id,ft_store_id,ft_station,ft_date,sum(ft_gs_qty) as ft_gs_qty,sum(ft_gs_amt) as ft_gs_amt," +
				"sum(ft_ns_qty) as ft_ns_qty,sum(ft_ns_amt) as ft_ns_amt,sum(ft_cash_id) as ft_cash_id," +
				"sum(ft_credit_id) as ft_credit_id,sum(ft_debit_id) as ft_debit_id,sum(ft_check_id) as ft_check_id," +
				"sum(ft_foodstamp_id) as ft_foodstamp_id,sum(ft_ebt_id) as ft_ebt_id,sum(ft_gc_id) as ft_gc_id," +
				"sum(ft_refund_qty) as ft_refund_qty,sum(ft_refund_amt) as ft_refund_amt,sum(ft_trn_count) as ft_trn_count," +
				"sum(ft_average) as ft_average,sum(ft_discount) as ft_discount,sum(ft_coupon) as ft_coupon," +
				"sum(ft_taxable_1) as ft_taxable_1,sum(ft_tax_1) as ft_tax_1,sum(ft_tax_exem_1) as ft_tax_exem_1," +
				"sum(ft_taxable_2) as ft_taxable_2,sum(ft_tax_2) as ft_tax_2,sum(ft_tax_exem_2) as ft_tax_exem_2," +
				"sum(ft_taxable_3) as ft_taxable_3,sum(ft_tax_3) as ft_tax_3,sum(ft_tax_exem_3) as ft_tax_exem_3," +
				"sum(ft_taxable_4) as ft_taxable_4,sum(ft_tax_4) as ft_tax_4,sum(ft_tax_exem_4) as ft_tax_exem_4," +
				"sum(ft_taxable_5) as ft_taxable_5,sum(ft_tax_5) as ft_tax_5,sum(ft_tax_exem_5) as ft_tax_exem_5," +
				"sum(ft_taxable_6) as ft_taxable_6,sum(ft_tax_6) as ft_tax_6,sum(ft_tax_exem_6) as ft_tax_exem_6," +
				"ft_user_id,sum(ft_rounding) as ft_rounding,sum(ft_vdr_coupon) as ft_vdr_coupon from t_fixed_total_rpt" +
				" where ft_date = '" + Date + "' and ft_user_id = '" + UserId + "' group by ft_date order by ft_id";
		SQLiteDatabase db = DBHelper.getWritableDatabase();
		Cursor cursor = db.rawQuery(sql, null);
		if(cursor == null) return list;
		while (cursor.moveToNext()) {
			int ft_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.ID));
			int ft_store_id = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STORE_ID));
			int ft_station = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.STATION));
			String ft_date = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DATE));
			int ft_gs_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_QTY));
			double ft_gs_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GS_AMT));
			int ft_ns_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_QTY));
			double ft_ns_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.NS_AMT));
			double ft_cash_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CASH_ID));
			double ft_credit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CREDIT_ID));
			
			double ft_debit_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DEBIT_ID));
			double ft_check_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.CHECK_ID));
			double ft_foodstamp_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FOODSTAMP_ID));
			double ft_ebt_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.EBT_ID));
			double ft_gc_id = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.GC_ID));
			int ft_refund_qty = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_QTY));
			double ft_refund_amt = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.REFUND_AMT));
			int ft_trn_count = cursor.getInt(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TRN_COUNT));
			double ft_average = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.AVERAGE));
			double ft_discount = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.DISCOUNT));
			
			double ft_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.COUPON));
			double ft_taxable_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_1));
			double ft_tax_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_1));
			double ft_tax_exem_1 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_1));
			double ft_taxable_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_2));
			double ft_tax_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_2));
			double ft_tax_exem_2 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_2));
			double ft_taxable_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_3));
			double ft_tax_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_3));
			double ft_tax_exem_3 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_3));
			
			double ft_taxable_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_4));
			double ft_tax_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_4));
			double ft_tax_exem_4 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_4));
			double ft_taxable_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_5));
			double ft_tax_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_5));
			double ft_tax_exem_5 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_5));
			double ft_taxable_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAXABLE_6));
			double ft_tax_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_6));
			double ft_tax_exem_6 = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.TAX_EXEM_6));
			String ft_user_id = cursor.getString(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_USER_ID));
			double ft_rounding = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_ROUNDING));
			double ft_vdr_coupon = cursor.getDouble(cursor.getColumnIndex(DatabaseSchema.FixedTotalRpt.FT_VDR_COUPON));
			
			list.add(new FixedTotalRpt(ft_id, ft_store_id, ft_station, ft_date, ft_gs_qty, ft_gs_amt, 
					ft_ns_qty, ft_ns_amt, ft_cash_id, ft_credit_id, ft_debit_id, ft_check_id, ft_foodstamp_id, 
					ft_ebt_id, ft_gc_id, ft_refund_qty, ft_refund_amt, ft_trn_count, ft_average, ft_discount, 
					ft_coupon, ft_taxable_1, ft_tax_1, ft_tax_exem_1, ft_taxable_2, ft_tax_2, ft_tax_exem_2, 
					ft_taxable_3, ft_tax_3, ft_tax_exem_3, ft_taxable_4, ft_tax_4, ft_tax_exem_4, ft_taxable_5, 
					ft_tax_5, ft_tax_exem_5, ft_taxable_6, ft_tax_6, ft_tax_exem_6, ft_user_id,ft_rounding,ft_vdr_coupon));
		}
		cursor.close();
		return list;
	}
	
	public void ShowMessage(String text, int type, int icon) {
		mMessageDialog = new MessageDialog(context);
		mMessageDialog.setStyle(type);
		mMessageDialog.setMessageIcon(icon);
		mMessageDialog.setMessage(text);
		mMessageDialog.setOnClickMessageListener(onClickMessageListener);
		mMessageDialog.show();
	}
	private OnClickMessageListener onClickMessageListener = new OnClickMessageListener() {

		@Override
		public void onClickYes() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onClickNo() {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onClickOK() {
			// TODO Auto-generated method stub
			mMessageDialog.dismiss();
		}
	};
}
